package com.javapc.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;

import com.javapc.test.Article;


public class GetSpeech {
    
	//guolin_blog
	//smartStudent1
	//http://blog.csdn.net/smartStudent1
    private static final String URL = "https://user.qzone.qq.com/2364988616";
    

    public static void main(String[] args) throws IOException {
        Connection conn = Jsoup.connect(URL)
                .userAgent("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0")
                .timeout(5000)
                .method(Connection.Method.GET);
        Document doc = conn.get();
        Element body = doc.body();
        
        System.out.println(body.getElementById("host_home_feeds"));
        //int totalPage=1;//默认该博主文章只有一页
        /*if(body.getElementById("host_home_feeds")!=null){
        	
        	
        }else{
        	System.out.println("该网友没有动态！");
        }
        int pageNow = 1;
        List<Article> articleList = new ArrayList<Article>();
        for(pageNow = 1; pageNow <= totalPage; pageNow++){
            articleList.addAll(getArtitcleByPage(pageNow));
        }
        

        for(Article article : articleList) {
            System.out.println("文章标题:" + article.getTitle());
            System.out.println("文章绝对路径地址:http://blog.csdn.net" + article.getAddress());
            System.out.println("文章简介:" + article.getDesption());
            System.out.println("发表时间:" + article.getTime());
            System.out.println("阅读量:" + article.getReadnums());
            System.out.println("评论数:" + article.getComments());
        }*/
    }

    public static List<Article> getArtitcleByPage(int pageNow) throws IOException{

        Connection conn = Jsoup.connect(URL + "/article/list/" + pageNow)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; rv:47.0) Gecko/20100101 Firefox/47.")
                .timeout(5000)
                .method(Connection.Method.GET);
        Document doc = conn.get();
        Element body = doc.body();
        List<Article> resultList = new ArrayList<Article>();

        Element articleListDiv = body.getElementById("article_list");
        Elements articleList = articleListDiv.getElementsByClass("list_item");
        for(Element article : articleList){
            Article articleEntity = new Article();
            Element linkNode = (article.select("div h1 a")).get(0);         
            Element desptionNode = (article.getElementsByClass("article_description")).get(0);
            Element articleManageNode = (article.getElementsByClass("article_manage")).get(0);
            

            articleEntity.setAddress(linkNode.attr("href"));
            articleEntity.setTitle(linkNode.text());
            articleEntity.setDesption(desptionNode.text());
            articleEntity.setTime(articleManageNode.select("span:eq(0").text());
            articleEntity.setReadnums(articleManageNode.select("span:eq(1").text());
            articleEntity.setComments(articleManageNode.select("span:eq(2").text());

            resultList.add(articleEntity);
        }
        return resultList;
    }
}